home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / GETKEYS.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  75 lines

  1. ############################################################################
  2. #
  3. #    File:     getkeys.icn
  4. #
  5. #    Subject:  Procedures to get keys for a gettext file
  6. #
  7. #    Author:   Richard L. Goerwitz
  8. #
  9. #    Date:     July 9, 1991
  10. #    
  11. ###########################################################################
  12. #
  13. #    Version:  1.2
  14. #
  15. ###########################################################################
  16. #
  17. #  Getkeys(FNAME) generates all keys in FNAME in order of occurrence.
  18. #  See gettext.icn for a description of the requisite file structure
  19. #  for FNAME.
  20. #
  21. ############################################################################
  22. #
  23. #  Links: adjuncts
  24. #
  25. #  Requires: UNIX (maybe MS-DOS; untested)
  26. #
  27. #  See also gettext.icn
  28. #
  29. ############################################################################
  30.  
  31. # declared in adjuncts.icn
  32. # global _slash, _baselen
  33.  
  34. procedure getkeys(FNAME)
  35.  
  36.     local line, intext, start_unindexed_part
  37.     initial {
  38.     if /_slash then {
  39.         if find("UNIX"|"Amiga", &features) then {
  40.         _slash := "/"
  41.         _baselen := 10
  42.         }
  43.         else if find("MS-DOS", &features) then {
  44.         _slash := "\\"
  45.         _baselen := 8
  46.         }
  47.         else stop("getkeys:  OS not supported")
  48.     }
  49.     }
  50.  
  51.     /FNAME & stop("error (getkeys):  null argument")
  52.  
  53.     # Try to open index file (there may not be one).
  54.     if intext := open(Pathname(FNAME) || getidxname(FNAME)) then {
  55.     # If there's an index file, then just suspend all the keys in
  56.     # it (i.e. suspend every line except the first, upto the tab).
  57.     # The first line tells how many bytes in FNAME were indexed.
  58.     # save it, and use it to seek to unindexed portions later on.
  59.     start_unindexed_part := integer(read(intext))
  60.     while line := read(intext) do
  61.         line ? suspend tab(find("\t")) \ 1
  62.     close(intext)
  63.     }
  64.  
  65.     intext := open(FNAME) | stop("getkeys:  ",FNAME," not found")
  66.     seek(intext, \start_unindexed_part | 1)
  67.     while line := read(intext) do
  68.     line ? { suspend (="::", tab(0)) \ 1 }
  69.  
  70.     # Nothing left to suspend, so fail.
  71.     fail
  72.  
  73. end
  74.  
  75.